package com.bw.shoppingmall.timmer;


import android.os.Handler;
import android.os.Message;

import androidx.annotation.NonNull;


import com.bw.shoppingmall.mvvm.viewmodel.SplashViewModel;

import java.lang.ref.WeakReference;

public class TimeHandler extends Handler {
    private int index = 3;
    private WeakReference<SplashViewModel> weakReference;

    public TimeHandler(SplashViewModel viewModel){
        weakReference = new WeakReference<>(viewModel);

    }

    @Override
    public void handleMessage(@NonNull Message msg) {
        super.handleMessage(msg);
        if (weakReference == null){
            return;
        }
        if (weakReference.get() == null){
            return;
        }
        if (msg.what == 0){
            index -= 1;
            weakReference.get().timeObserable.set(index+"s");
        }else {
            weakReference.get().SkipTimmer();
        }
    }
}
